package com.ourteam.product.api;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.IProductUITableColumnDAO;
import com.ourteam.product.ui.dao.ProductUITableColumnDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUITableColumnBean;

public class ProductUITableFieldSearchModel extends AbstractSearchModel<ProductUITableColumnDAOQueryBean> {

	private long tableId;

	public long getTableId() {
		return tableId;
	}

	public void setTableId(long tableId) {
		this.tableId = tableId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUITableColumnBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUITableColumnDAOQueryBean queryBean) throws Exception {

		ProductUITableColumnDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (tableId != 0) {
			criteria.andTableIdEqualTo(tableId);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IProductUITableColumnDAO.SortIndex);
		}

	}

}
